#ifndef BOOKLIST_H
#define BOOKLIST_H

#include <QWidget>
#include <QtMqtt/qmqttclient.h>
#include <QSqlTableModel>
#include <QDateTime>  // 添加头文件

QT_BEGIN_NAMESPACE
namespace Ui {
class BookList;
}
QT_END_NAMESPACE

class BookList : public QWidget
{
    Q_OBJECT

public:
    explicit BookList(QWidget *parent = nullptr);
    ~BookList();

protected:
    QMqttClient *pMqttClient;

private slots:
    void updateLogStateChange();
    void recv_message(const QByteArray &message, const QMqttTopicName &topic);
    void onMqttConnected();  // 新增的槽函数声明

    void on_searchButton_clicked();
    void on_addBookButton_clicked();
    void on_deleteButton_clicked();
    void on_refreshButton_clicked();  // 新增的槽函数声明

    void on_refreshButton_3_clicked();

    void on_refreshButton_4_clicked();

    void on_refreshButton_2_clicked();

    void on_deleteButton_2_clicked();

private:
    Ui::BookList *ui;
    QSqlTableModel *model;
    QDateTime lastDeleteTime;  // 添加成员变量

    void updateUser(const QString &username, const QString &rfid_tag);
    void deleteLibraryUserByRfid(const QString &rfid_tag);
    void updateAvailability(const QString &rfid_tag);
    void updateBookAvailability(const QString &rfid_tag, const QString &available, const QString &title, const QString &author, const QString &isbn);
};

#endif // BOOKLIST_H
